import socket as so
import time as t
import threading as td

so = so.socket()
so.bind(("192.168.223.6", 7999))
so.listen(5)
print("服务器已运行")

online_usr_list = []

def boardcast(ip,recv_text):
    for usr in online_usr_list:
        usr.sendall(f"IP为{ip}的用户说：{recv_text}".encode())
def session_deed(con,ip):
    print(f"{ip}已登录")
    while True:
        recv_text = con.recv(1024).decode("utf-8")
        t.sleep(0.3)
        # con.sendall(f"IP为{ip}的用户说：{recv_text}".encode())
        boardcast(ip,recv_text)

while True:
    con, ip = so.accept()
    online_usr_list.append(con)
    c_td = td.Thread(target=session_deed,args=(con,ip))
    c_td.start()


# con.close()
# so.close()
